package com.ce.pms.log4ce;

import java.util.List;
import java.util.Map;

import org.aspectj.lang.JoinPoint;

import com.ce.common.util.BlankUtil;
import com.ce.component.log4ce.aop.constructor.support.AbstractBizDescriptionHandler;
import com.ce.component.log4ce.aop.constructor.support.BizDescriptionHandler;
import com.ce.component.log4ce.aop.parser.BizLogParser;
import com.ce.pms.customer.vo.CustomerHouseVO;
import com.ce.pms.customer.vo.CustomerVO;
import com.ce.pms.customer.vo.IndividualVO;
import com.ce.pms.customer.vo.OrganizationVO;

public class CustomerAddHandler extends AbstractBizDescriptionHandler implements BizDescriptionHandler {

	@Override
	public Map<String, Object> getNamedParametersMap(JoinPoint joinPoint, Object obj, BizLogParser logParser) {

		Map<String,Object> map = logParser.getLogArguments(joinPoint);
		List<CustomerHouseVO> houseList = (List<CustomerHouseVO>)map.get("houseList");
		List<CustomerVO> customerList = (List<CustomerVO>)map.get("customerList");
		StringBuffer sb = new StringBuffer();
		if(!BlankUtil.isBlank(houseList) && !BlankUtil.isBlank(customerList))
		{
			for(CustomerHouseVO houseVO : houseList)
			{
				String houseNumber = houseVO.getHouseNumber();
				for(CustomerVO customerVO : customerList)
				{
					CustomerRecord record = new CustomerRecord();
					record.setHouseNumber(houseNumber);
					if(CustomerVO.INDIVIDUAL_CODE.equals(customerVO.getParticipantTypeCode())){
						//处理个人业主
						IndividualVO individualVO = (IndividualVO)customerVO;
						record.setOwnerName(individualVO.getParticipantName() == null?"":individualVO.getParticipantName());
						record.setCertificateName(individualVO.getCertificateTypeName() == null?"":individualVO.getCertificateTypeName());
						record.setCertificateNo(individualVO.getCertificateNo() == null?"":individualVO.getCertificateNo());
						record.setTelephone(individualVO.getTelephone() == null?"":individualVO.getTelephone());
						sb.append(record.toString());
					}else if(CustomerVO.ORGNIZATION_CODE.equals(customerVO.getParticipantTypeCode())) {
						//处理个组织业主
						record.setOrganization(true);
						OrganizationVO organizationVO = (OrganizationVO)customerVO;
						record.setOrgName(organizationVO.getParticipantName() == null ?"":organizationVO.getParticipantName());
						record.setOrgAddress(organizationVO.getAddress() == null?"":organizationVO.getAddress());
						record.setOrgTelephone(organizationVO.getTelephone() == null?"":organizationVO.getTelephone());
						record.setOrgContactPerson(organizationVO.getOrganizationLinkMan() == null?"":organizationVO.getOrganizationLinkMan());
						record.setOrgZipcode(organizationVO.getZip() == null?"":organizationVO.getZip());
						sb.append(record.toString());
					}
					sb.append(CustomerRecord.OUTER_SPLIT_TEXT);
				}
			}
		}
		sb = sb.deleteCharAt(sb.length()-1);
		map.put("addingOperationInfo", sb.toString());
		map.putAll(logParser.getLogStaticContents(joinPoint));
		return map;
	}
}
